package com.dfec.water.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dfec.component.uid.core.service.UidService;
import com.dfec.framework.mybatis.core.page.PageParam;
import com.dfec.framework.mybatis.core.page.PageUtils;
import com.dfec.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.dfec.water.dao.YdbWarnDeviceDao;
import com.dfec.water.entity.YdbDeviceTypeEntity;
import com.dfec.water.entity.YdbWarnDeviceEntity;
import com.dfec.water.service.YdbWarnDeviceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author df
 * @title: YdbDeviceTypeDictServiceImpl
 * @description: 预警设备数据
 * @date Thu Feb 06 11:10:12 CST 2025
 */
@Service
public class YdbWarnDeviceServiceImpl extends ServiceImpl<YdbWarnDeviceDao, YdbWarnDeviceEntity> implements YdbWarnDeviceService {

    @Resource
    private  YdbWarnDeviceDao warnDeviceDao;

    @Resource
    private  UidService uidService;

    /**
     * 分页查询
     *
     * @param pageParam 入参
     * @return PageUtils
     * @author df
     * @date Thu Feb 06 11:10:12 CST 2025
     */
    @Override
    public PageUtils queryPage(PageParam<YdbWarnDeviceEntity> pageParam) {
        return warnDeviceDao.selectPage(pageParam);
    }

    /**
     * 不带分页查询
     *
     * @param YdbWarnDeviceEntity 入参
     * @return List<YdbWarnDeviceEntity>
     * @author df
     * @date Thu Feb 06 11:10:12 CST 2025
     */
    @Override
    public List<YdbWarnDeviceEntity> listAll(YdbWarnDeviceEntity YdbWarnDeviceEntity) {
        return warnDeviceDao.selectAll(YdbWarnDeviceEntity);
    }

    @Override
    public boolean save(YdbWarnDeviceEntity entity) {
        entity.setId(uidService.next());
        return super.save(entity);
    }



    @Override
    public List<Map<String, Object>> getWarnProject() {
        return warnDeviceDao.getWarnProject();
    }


    @Override
    public List<YdbDeviceTypeEntity> getProjectWarnDevice(Long projectId) {
        return warnDeviceDao.getProjectWarnDevice(projectId);
    }


    @Override
    public Map<String,Object> getWarnData(Long deviceId) {
        List<Map<String, Object>> deviceData = this.warnDeviceDao.getDeviceData(deviceId);
        if(deviceData.isEmpty()){
            return new HashMap<>();
        }
        return deviceData.get(0);
    }

    @Override
    public List<Map<String,Object>> getTopTen(){
        return this.warnDeviceDao.getTopTen();
    }

}